package cn.zwk.drawing.domain.rendering.model;

import lombok.Data;
import lombok.Builder;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 渲染结果领域实体
 */
@Data
@Builder
public class RenderResult {
    
    /**
     * 渲染ID
     */
    private String renderId;
    
    /**
     * 源PlantUML内容的哈希
     */
    private String sourceHash;
    
    /**
     * 渲染后的SVG内容
     */
    private String svgContent;
    
    /**
     * 渲染状态
     */
    private RenderStatus status;
    
    /**
     * 错误信息（如果有）
     */
    private String errorMessage;
    
    /**
     * 渲染耗时（毫秒）
     */
    private Long renderTime;
    
    /**
     * 节点位置信息
     */
    private List<NodeGeometry> nodeGeometries;
    
    /**
     * 渲染时间
     */
    private LocalDateTime renderedAt;
    
    /**
     * 渲染状态枚举
     */
    public enum RenderStatus {
        SUCCESS("success", "成功"),
        FAILED("failed", "失败"), 
        TIMEOUT("timeout", "超时"),
        INVALID_SYNTAX("invalid_syntax", "语法错误");
        
        private final String code;
        private final String description;
        
        RenderStatus(String code, String description) {
            this.code = code;
            this.description = description;
        }
        
        public String getCode() { return code; }
        public String getDescription() { return description; }
    }
    
    /**
     * 检查渲染是否成功
     */
    public boolean isSuccess() {
        return RenderStatus.SUCCESS.equals(status);
    }
    
    /**
     * 获取指定节点的几何信息
     */
    public NodeGeometry getNodeGeometry(String nodeId) {
        if (nodeGeometries == null) return null;
        return nodeGeometries.stream()
                .filter(geo -> nodeId.equals(geo.getNodeId()))
                .findFirst()
                .orElse(null);
    }
}